* Table C7: Program characteristics by excess self-funded capacity at the benchmark

********************************************************************************
************************** Prepare data ****************************************
********************************************************************************

do "${dir_code}/helpers/TableC7_helper.do"

********************************************************************************
************************** Prepare table ***************************************
********************************************************************************

cap file close sumstat
file open sumstat using "${tableC7}", write replace
file write sumstat "\begin{tabular}{l c c c c c c c c} \\ \hline\hline" _n
file write sumstat " & \multicolumn{2}{c}{Programs with no excess} & & \multicolumn{2}{c}{Programs with excess} & & \multicolumn{2}{c}{Programs with excess} \\ " _n
file write sumstat " & \multicolumn{2}{c}{self-funded capacity} & & \multicolumn{2}{c}{self-funded capacity} & & \multicolumn{2}{c}{self-funded capacity (weighted)} \\ \cline{2-3}\cline{5-6}\cline{8-9}" _n
file write sumstat " & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)}  \\ \hline" _n
	
	foreach var of varlist periphery fulltime field_4 field_3 ///
		field_8 field_17 field_18 {
		local lab_var: variable label `var'
		
		forvalues i = 0/1 {
			qui sum `var' if potential_binary == `i'
			local mean_`i': display %4.2f r(mean)
			local sd_`i': display %4.2f r(sd)
			
			qui sum `var' [fweight = potential] if potential_binary == `i'
			local mean_w_`i': display %4.2f r(mean)
			local sd_w_`i': display %4.2f r(sd)
		}
		
		file write sumstat "`lab_var' & `mean_0' & (`sd_0') & & `mean_1' & (`sd_1') & & `mean_w_1' & (`sd_w_1') \\ " _n
	}
	
	forvalues i = 0/1 {
		qui sum ps_cutoff if potential_binary == `i'
		local mean_`i': display %4.2f r(mean)
		local sd_`i': display %4.2f r(sd)
		
		qui sum ps_cutoff [fweight = potential] if potential_binary == `i'
		local mean_w_`i': display %4.2f r(mean)
		local sd_w_`i': display %4.2f r(sd)
	}
	
	file write sumstat "State-funded priority-score cutoff (scale: 0--144) & `mean_0' & (`sd_0') & & `mean_1' & (`sd_1') & & `mean_w_1' & (`sd_w_1') \\ " _n
	
	forvalues i = 0/1 {
		qui sum potential if potential_binary == `i'
		local count_`i': display %4.0f r(N)
		local sum_`i': display %4.0f r(sum)
		local mean_`i': display %4.2f r(mean)
		local sd_`i': display %4.2f r(sd)
		local sum_`i': display %4.0f r(sum)
	}
	
	file write sumstat "\hline Excess self-funded seats per program & `mean_0' & (`sd_0') & & `mean_1' & (`sd_1') & & `mean_1' & (`sd_1') \\" _n
	file write sumstat "\# number of programs & `count_0' & - & & `count_1' & - & & `count_1' & - \\ \hline\hline" _n
	file write sumstat "\multicolumn{9}{p{21.5cm}}{{\it Notes}: The table presents means and standard deviations of various characteristics of programs with and without excess self-funded capacity at the benchmark. Columns (1)--(4) use equal weights, while columns (5)--(6) weight programs by the number of excess self-funded seats at the benchmark. Standard deviations are in parentheses.}"
file write sumstat "\end{tabular}" _n
file close sumstat
